﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVC5Test.Controllers
{
    public class ResponseDataTypesController : Controller
    {
        /**
         * MVC返回的内容：
         * ViewResult 返回对应
         * ConctentResult 返回字符串
         * RedirectResult 重定向
         * RedirectToRouteResult 根据路由重定向
         * FileResult 返回文件
         * JsonResult 返回JSON
         * HttpStatusCodeResult 返回状态码对应页面
         * PartialViewResult 返回部分页面同时用来充当组件使用的
         */
        // GET: ResponseDataTypes
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult ContentData()
        {
            return Content("返回一个字符串！");
        }

        public ActionResult RedirectView()
        {
            return Redirect("http://www.baidu.com");
        }

        public ActionResult RedirectAction()
        {
            return RedirectToAction("Index");
        }

        public ActionResult FileData(string fileName)
        {
            return File(Request.MapPath($@"~/Upload/Picture/{fileName}"), "image/jpg");
        }

        public ActionResult JsonData()
        {
            return Json(new { Id = "123", Name = "zhaichao" }, JsonRequestBehavior.AllowGet);
        }

        public PartialViewResult PartialView()
        {
            return PartialView("_partial");
        }

        /// <summary>
        /// 这种方式无法返回到界面中
        /// </summary>
        /// <returns></returns>
        public string GetString()
        {
            return "获取一个字符串";
        }
    }
}